package top.ytazwc.improve;

import top.ytazwc.improve.service.ICommodity;
import top.ytazwc.improve.service.impl.CardCommodityService;
import top.ytazwc.improve.service.impl.CouponCommodityService;
import top.ytazwc.improve.service.impl.GoodsCommodityService;

/**
 * @author 花木凋零成兰
 * @title StoreFactory
 * @date 2024/4/28 11:19
 * @package top.ytazwc.improve
 * @description 奖品工厂
 */
public class StoreFactory {
    /**
     * 奖品类型实例化
     * @param commodityType 奖品类型
     * @return  实例化对象
     */
    public ICommodity getCommodityService(Integer commodityType) {
        if (commodityType == null) {
            return null;    // 排除空
        }
        if (commodityType == 1) {
            return new CouponCommodityService();
        }
        if (commodityType == 2) {
            return new GoodsCommodityService();
        }
        if (commodityType == 3) {
            return new CardCommodityService();
        }
        // 否则 为不存在的类型
        throw new RuntimeException("不存在的奖品服务类型");
    }
    /**
     * 奖品类信息方式实例化
     * @param clazz 奖品类
     * @return      实例化对象
     */
    public ICommodity getCommodityService(Class<? extends ICommodity> clazz) throws IllegalAccessException, InstantiationException {
        if (null == clazz) {
            return null;
        }
        return clazz.newInstance();
    }
}
